class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> heap(stones.begin(), stones.end());
        while(heap.size() > 1)
        {
            int x1 = heap.top();
            heap.pop();
            int x2 = heap.top();
            heap.pop();
            heap.push(x1 - x2);
        }
        return heap.empty() ? 0 : heap.top();
    }
};